package com.example.xwen.weight;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.Button;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    public static String sex = "male";
    private String str_height;
    private EditText et;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button b= (Button) findViewById(R.id.submitContent);
        et = (EditText) findViewById(R.id.editContent);
        b.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View arg0){
                RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup);
                str_height = et.getText().toString();

                if("".equals(str_height)){
                    Toast.makeText(MainActivity.this,"身高不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                double height = Double.parseDouble(str_height);
                rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
                    @Override
                    public void onCheckedChanged(RadioGroup arg0,int checkedId){
                        if(checkedId == R.id.radioGroup){
                            sex = "male";
                        }else{
                            sex = "female";
                        }
                        Log.i("x",sex);
                    }
                });
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,weight.class);
                Bundle bundle = new Bundle();
                bundle.putDouble("height",height);
                bundle.putString("sex",sex);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
